package a_File1;

import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class FileTest2 {
    //方式一: 默认位置生成
    @Test
    public void pathTest1(){
        File file = new File("a.txt");
        String path = file.getAbsolutePath();
        //D:\Idea-workspace\api_2207\api_day09\a.txt
        System.out.println(path);
    }
    //方式二: 获取在和本类的同包下b.txt
    @Test
    public void pathTest2(){
        String path = FileTest2.class.getResource("b.txt").getPath();

        System.out.println(path);
    }
    //方式二: 获取scr下的c.txt
    @Test
    public void pathTest3() throws IOException {
        File file2 = new File("src/c1.txt");
        File file3 = new File("src/c2.txt");
        file2.createNewFile();
        file3.createNewFile();
        String path = FileTest2.class.getClassLoader().getResource("c.txt").getPath();
        String path2 = FileTest2.class.getClassLoader().getResource("c1.txt").getPath();
        System.out.println(path);
        System.out.println(path2);
    }
}
